package com.frcdi.qms.material.service;

import com.frcdi.qms.material.domain.InboundRecord;
import com.frcdi.qms.material.domain.Materials;
import com.frcdi.qms.material.mapper.InboundRecordMapper;
import com.frcdi.qms.material.mapper.MaterialsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName InboundService
 * @Author Mr.Han
 * @Description //TODO $
 * @create 2024/7/8 17:39
 **/
@Service
public class InboundService {
    @Autowired
    private InboundRecordMapper inboundRecordMapper;
    @Autowired
    private MaterialsMapper materialMapper;

    public void addInboundRecord(InboundRecord record) {
        inboundRecordMapper.insert(record);
        Materials material = materialMapper.selectById(record.getMaterialId());
        material.setRemainingQuantity(material.getRemainingQuantity() + record.getQuantity());
        materialMapper.update(material);
    }

    public List<InboundRecord> getInboundRecordsByMaterialId(Integer materialId) {
        return inboundRecordMapper.selectByMaterialId(materialId);
    }
}
